package universe;

import junit.framework.TestCase;

public class BlockHandlerTest extends TestCase {

	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testBlockHandler() {
		Block bl = Block.getRandomBlock();
		Board bo = new Board(10, 10);
		BlockHandler bh = new BlockHandler(bl, bo);
		
		assertTrue(bh instanceof BlockHandler);
	}

	public void testGoDown() {
		fail("Not yet implemented");
	}

	public void testGoLeft() {
		fail("Not yet implemented");
	}

	public void testGoRight() {
		fail("Not yet implemented");
	}

	public void testRotation() {
		Block b = new Block(Utils.getBlockA());
		for(int i = 0; i<10 ; i++){
			int pos = b.getCurrentPosition();
			b.rotate();
			assertTrue(b.getCurrentPosition() == (pos+1)%4);
		}
	}

	public void testGetX() {
		Block bl = Block.getRandomBlock();
		Board bo = new Board(10, 10);
		BlockHandler bh = new BlockHandler(bl, bo); 
		
		int x 	= bh.getX();
		assertTrue(x > 0 && x < bo.getWidth());
	}

	public void testSetX() {
		Block bl = Block.getRandomBlock();
		Board bo = new Board(10, 10);
		BlockHandler bh = new BlockHandler(bl, bo);
		
		bh.setX(5);
		assertTrue(bh.getX() == 5);
	}

	public void testGetY() {
		Block bl = Block.getRandomBlock();
		Board bo = new Board(10, 10);
		BlockHandler bh = new BlockHandler(bl, bo); 
		
		int y 	= bh.getY();
		assertTrue(y > 0 && y < bo.getHeight());
	}

	public void testSetY() {
		Block bl = Block.getRandomBlock();
		Board bo = new Board(10, 10);
		BlockHandler bh = new BlockHandler(bl, bo);
		
		bh.setY(10);
		assertTrue(bh.getY() == 10);
	}

	public void testGetB() {
		Block bl = Block.getRandomBlock();
		Board bo = new Board(10, 10);
		BlockHandler bh = new BlockHandler(bl, bo);
		
		assertTrue(bh.getB() instanceof Block);
	}

	public void testSetB() {
		Block bla = new Block(Utils.getBlockA());
		Board bo = new Board(10, 10);
		BlockHandler bh = new BlockHandler(bla, bo);
		
		Block blb = new Block(Utils.getBlockB());
		bh.setB(blb);
		
		assertTrue(bh.getB().equals(blb));
	}

	public void testGetBoard() {
		Block bl = Block.getRandomBlock();
		Board bo = new Board(10, 10);
		BlockHandler bh = new BlockHandler(bl, bo);
		
		assertTrue(bh.getBoard() instanceof Board);
	}

	public void testSetBoard() {
		Block bl = Block.getRandomBlock();
		Board boa = new Board(10, 10);
		BlockHandler bh = new BlockHandler(bl, boa);
		
		Board bob = new Board(20, 20);
		bh.setBoard(bob);
		
		assertTrue(bh.getBoard().equals(bob));
	}

}
